package com.rq.viewtestapplication.manager;

import android.graphics.Canvas;
import android.graphics.Paint;

import androidx.annotation.NonNull;

import com.rq.viewtestapplication.LineLink;
import com.rq.viewtestapplication.LinkImpl;
import com.rq.viewtestapplication.ViewInfo;

import java.util.ArrayList;
import java.util.List;

public class LinkManager {

    List<LinkImpl> linkInfos;

    public void createLink(@NonNull List<ViewInfo> childPosition) {
        if (childPosition.size() > 1) {
            if (linkInfos == null) {
                linkInfos = new ArrayList<>();
            }
            LineLink linkInfo = new LineLink();
            for (ViewInfo info : childPosition) {
                linkInfo.attach(info);
                linkInfos.add(linkInfo);
            }
        }
    }

    public void draw(Canvas canvas, Paint focus) {
        if (linkInfos != null && linkInfos.size() > 0) {
            for (LinkImpl linkInfo : linkInfos) {
                linkInfo.draw(canvas, focus);
            }
        }
    }
}
